var api = require('../../utils/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        arch: false,
        apipath: api.Apipath,
        keyword: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      var that = this;
      wx.request({
        url: api.Swipers,
        method: 'GET',
        success: function (res) {
          that.setData({
            imgUrls: res.data.data//首页轮播图
          })
        },
      })
      wx.request({
        url: api.Swipers + '?tid=2',
        method: 'GET',
        success: function (res) {
          that.setData({
            advImgUrls: res.data.data[0]//首页广告图
          })
        },
      })
      wx.request({
        url: api.DoctorsRec,
        method: 'GET',
        success: function (res) {
          that.setData({
            doctorsRec: res.data.data//医生推荐
          })
        },
      })
    },
    /*健康档案遮罩层*/
    archdown: function () {
        var that = this;
        that.setData({
            arch: true
        })

    },
    closed: function () {
        var that = this;
        that.setData({
            arch: false
        })
    },

    /*跳转页面*/
    consultation: function () {
        /*在线咨询 */
        wx.navigateTo({
            url: '/pages/consult/consult'
        })
    },
    assist: function () {
        /*协助就医 */
        wx.navigateTo({
            url: '/pages/assist/assist'
        })
    },
    record: function () {
        /*健康档案 */
        wx.navigateTo({
            url: '/pages/record/record'
        })
    },
    thinking: function () {
        /*医患心声 */
        wx.navigateTo({
            url: '/pages/thinking/thinking'
        })
    },
    lookmore:function(){
        /*查看更多 */
    wx.navigateTo({
      url: '/pages/search/search',
    })
    },
    seeDetails: function (e) {
      /*查看详情 */
      var $this = this;
      var id=e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/recommend/recommend?id='+id,
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    getSuggest: function (event) {
      var that = this;
      this.setData({
        keyword: that.trim(event.detail.value)
      })
    },
    search: function () {
      var that = this;
      var keyword = that.data.keyword;
      wx.request({
        url: api.Search,
        data: {
          userId: wx.getStorageSync('userid'),
          role: wx.getStorageSync('role'),
          keyword: keyword,
          page: 1,                   //初始页码
          pageSize: 10,
        },
        method: 'GET',
        success: function (res) {
          if (res.data.code == 200) {
            wx.navigateTo({
              url: '/pages/search/search?keyword=' + keyword
            });
          } else {
            wx.showToast({
              title: '搜索内容不存在',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })

    },
    inparch: function (e) {
      //获取健康档案查询条件
      this.setData({
        archkeywords: e.detail.value
      })
    },
    queding: function () {
      //确认查询
      var that = this;
      var keywords = that.data.archkeywords;
      console.log(keywords);
      //return  false;
      
      if (keywords=='') {
        wx.showToast({
          title: '查询条件不能为空',
          duration: 2000,
          icon: 'none'
        });
        return false;
      } else {
        wx.request({
          url: api.CheckArchSearch,
          data: {
            keywords: keywords,
          },
          method: 'Get',
          success: function (res) {
            if (res.data.code == 200) {
              wx.navigateTo({
                url: '/pages/hz_information/hz_infornation?id=' + res.data.id,
              })
            }else{
              wx.showToast({
                title: '查询档案不存在',
                duration: 2000,
                icon: 'none'
              });
            }
          }
        })
      }
    },
    // 去除首尾的空格
    trim: function (s) {
      return s.replace(/(^\s*)|(\s*$)/g, "");
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})